package com.module.codeBind.dao;

import java.lang.reflect.InvocationTargetException;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

import org.apache.commons.beanutils.PropertyUtils;
import org.hibernate.Session;

import base.common.CUDEnum;
import base.dao.GenericHibernateDao;

import com.module.codeBind.vo.BindBatchCode;
import com.module.codeBind.vo.BindBatchCodeSyn;

public class BindBatchCodeSynDao extends GenericHibernateDao<BindBatchCodeSyn,Long>{

	private static BindBatchCodeSynDao dao = new BindBatchCodeSynDao();
	private BindBatchCodeSynDao(){}
	public static BindBatchCodeSynDao getInstance(){
		return dao;
	}
	/**
	 * 新增绑定批次（添加增量表记录）
	 * @param session
	 * @param batchCodes
	 * @return
	 * @throws IllegalAccessException
	 * @throws InvocationTargetException
	 * @throws NoSuchMethodException
	 */
	public boolean saveSyn(Session session,List<BindBatchCode> batchCodes) 
	throws Exception{
		this.deleteSyn(session, batchCodes);
		for(Iterator it = batchCodes.iterator();it.hasNext();){
			BindBatchCodeSyn bean = new BindBatchCodeSyn();
			PropertyUtils.copyProperties(bean,it.next());
			bean.setSyscStatus(CUDEnum.C.toString());
			bean.setIssysc("1");
			bean.setSyscTime(new Date());
			session.save(bean);
		}
		return true;
	}

	/**
	 * 删除绑定批次（添加增量表记录）
	 * @param session
	 * @param batchCodes
	 * @return
	 */
	public boolean deleteSyn(Session session,List<BindBatchCode> batchCodes){
		
		boolean result = false;
		for(int i=0;i<batchCodes.size();i++){
			BindBatchCodeSyn bean = new BindBatchCodeSyn();
			bean.setId(batchCodes.get(i).getId());
			bean.setSyscStatus(CUDEnum.D.toString());
			bean.setIssysc("1");
			bean.setSyscTime(new Date());
			session.save(bean);
		}
		return result;
	}

}
